package com.runfast.waimai.service.impl;

import com.runfast.common.service.BaseService;
import com.runfast.waimai.dao.mapper.BasePurviewMapper;
import com.runfast.waimai.dao.mapper.WaiMaiRunfastAgentaccountsMapper;
import com.runfast.waimai.dao.model.WaiMaiRunfastAgentaccounts;
import com.runfast.waimai.dao.model.WaiMaiRunfastAgentaccountsExample;
import com.runfast.waimai.service.WaiMaiRunfastAgentaccountsService;
import org.apache.commons.lang3.Validate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WaiMaiRunfastAgentaccountsServiceImpl extends BaseService<WaiMaiRunfastAgentaccounts, Integer, WaiMaiRunfastAgentaccountsExample> implements WaiMaiRunfastAgentaccountsService {

    public List<WaiMaiRunfastAgentaccounts> selectByMapWithPageable(Map<Object,Object> map){
        WaiMaiRunfastAgentaccountsMapper waiMaiRunfastAgentaccountsMapper=(WaiMaiRunfastAgentaccountsMapper)this.mapper;
        return waiMaiRunfastAgentaccountsMapper.selectByMapWithPageable(map);
    }
    public Integer  countByMap(Map<Object,Object> map){
        WaiMaiRunfastAgentaccountsMapper waiMaiRunfastAgentaccountsMapper=(WaiMaiRunfastAgentaccountsMapper)this.mapper;
        return waiMaiRunfastAgentaccountsMapper.countByMap(map);
    }

    @Override
    public WaiMaiRunfastAgentaccounts findByaccounts(String accounts) {
        Validate.notBlank(accounts);
        WaiMaiRunfastAgentaccountsExample runfastAgentaccountsExample = new WaiMaiRunfastAgentaccountsExample();
        runfastAgentaccountsExample.createCriteria().andAccountsEqualTo(accounts);
        List<WaiMaiRunfastAgentaccounts> runfastAgentaccountss = this.selectByExample(runfastAgentaccountsExample);
        WaiMaiRunfastAgentaccounts runfastAgentaccounts =new WaiMaiRunfastAgentaccounts();
        if (runfastAgentaccountss.size()>0){
            runfastAgentaccounts = runfastAgentaccountss.get(0);
        }else{
            runfastAgentaccounts=null;
        }
        return runfastAgentaccounts;
    }

    public boolean updatePassword(Integer id,String password,String newPassword){
        WaiMaiRunfastAgentaccounts runfastAgentaccounts=new WaiMaiRunfastAgentaccounts();
        WaiMaiRunfastAgentaccountsExample runfastAgentaccountsExample=new WaiMaiRunfastAgentaccountsExample();
        runfastAgentaccountsExample.createCriteria().andIdEqualTo(id).andPasswordEqualTo(password);
        runfastAgentaccounts.setPassword(newPassword);
        int i=mapper.updateByExampleSelective(runfastAgentaccounts,runfastAgentaccountsExample);
        boolean fage=false;
        if(i==0){
            fage=false;
        }else if(i==1){
            fage=true;
        }
        return  fage;
    }


}